﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Levels;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using System.Threading;

namespace World
{
    public static class WorldManager
    {

        #region world
        //accelerometer reading
        public static Vector3 accReading;
        public static WorldConfig WorldConfig;
        public static bool IsHeatActive; //set to true if currently one of NPCs spotted avatar and heat is active
        public static int[] HeatRectangle;
        public static bool EverythingLoaded;
        public static List<Node> Nodes;

        #region avatar action menu
        public static bool IsAvatarActionMenuOpen;
        public static double ElapsedMs1; //elapsed miliseconds since avatar action menu has been opened
        public static bool ActionIconHighlighted;
        public static Util.Helpers.PublicEnums.ActionButtonClicked ActionButtonClicked;
        public static bool AllButtonsFitTheRightSide = true;
        #endregion

        #region AWarding points
        public static int AcheivementStringStep;
        public static int PointsStringStep;
        public static bool AddingPoints;
        public static bool AwardingAnimationOn;
        public static float AwardPointsAlphaValue; //starts with 1
        public static float AlphaIncrementor;//default 0.1
        public static string AcheivementInfo;
        public static string AcheivementPoints;
        public static bool PointsAdded; //when points are added, and awarding points animation is done, make points text gold and glow for a moment
        public static double PointsGlowTimer; //stop showing glow on points after x miliseconds
        public static int PointsToAdd; //number of points to add for the achievement
        public static int PointsBeforeAwarding; //number of points before awarding anymore
        public static bool DoNotAddPoints;
        public static int[] AwardingColor;
        #endregion

        #region Showing slide in information
        public static bool SlidingInInformation;
        public static float R;
        public static float G;
        public static float B;
        public static float A;
        #endregion

        #region bomb related
        public static Util.Classes.Bomb BombInstanceBeingDefused;
        #endregion

        #region time related
        public static bool TimeSubtracted;

        #endregion

        #region breath progress bar
        public static Rectangle BreathProgressBar1;
        public static Rectangle BreathProgressBar2;
        public static double CurrentTimeElapsed; //needed because breath is taken every x seonds
        public static bool BreathTimeElapsedSet;
        public static int BreathProgressBarWidth;
        public static string WaterObstacle;//obstacle that avatar is on top off, and that's why breath is being taken away
        #endregion

        #region powerups
        public static List<Util.Classes.Powerup> Powerups;

        #endregion

        #region properties
        public static bool PauseON; //set to true, if pause is on
        //public static int Points;
        public static bool IsDefusingBomb; //set to true if avatar currently is defusing the bomb
        public static string BombBeingDefused; //name / ID of the bomb that is being defused
        public static bool WiresShown;
        public static double ElapsedDefusingWireGracePeriod;//how much time elapsed since first, defusing wire has been shown
     
        //time left
        public static int MinutesLeft;
        public static int SecondsLeft;
        ////collision detection
        //public static Util.Helpers.PublicEnums.CollisionDirection CollsionDetectionDirection;
       

        #endregion

        #region inventory
        public static List<Util.Classes.InventoryItem> Inventory;
        public static List<Util.Classes.InventorySlot> InventorySlots;
        public static Vector2 EvenSlotPos;
        public static Vector2 OddSlotPos;
        public static bool UsingItem;
        public static Util.Classes.BombScannerInventory BombScanner;
        public static Util.Classes.ScannedNodesMapInventory ScannerMap;
        public static Util.Classes.AutoScannerInventory AutoScannerInventory;

        public static bool InventoryClosed;

        #endregion

        #region item using/actions

        #region THROWING
        public static bool DrawThrowFieldOfReachFlag;
        public static bool ThrowFieldOfReachReady;
        public static Rectangle FieldOfThrowReachRect;
        public static Vector2 ThrowPosition;//where to throw the bottle
        public static Util.Classes.Item ThrownItem;
        public static bool ThrowComplete;
        public static double CurrentElapsedTimeUponThrowComplete;
        public static List<Characters.NPC> NPCToDistract;//list of npcs that are in throw range and can possibly be distracted
        public static List<Util.Classes.FieldOfViewBackup> StoredFOVs;
        public static bool ThrowDirectionChosen;
        #endregion

        #region INTERACTION BUTTON
        public static bool ObstacleInteractionButtonPressed;


        #endregion

        #endregion

        #region bomb scanner map
        public static int RedMarkerCount;
        public static int OrangeMarkerCount;
        public static int GreenMarkerCount;

        #endregion


        #endregion


        #region methods

        /// <summary>
        /// Get map cell instance by name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Levels.MapCell GetMapCellInstanceByName(string name)
        {
            return Levels.LevelManager.GetMapCellByName(name);

        }

        //public static int GetObstacleWidth

        /// <summary>
        /// Get obstacle to draw instance
        /// by related obstacle's ID (name)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Util.Classes.ObstacleToDraw GetObstacleToDrawByName(string name)
        {
            return Levels.LevelManager.GetObstacleToDrawByName(name);

        }


        /// <summary>
        /// Show sliding in information
        /// </summary>
        /// <param name="achievementType"></param>
        /// <param name="points"></param>
        public static void SlideInfoIn(string information, float r,float g,float b,float a)
        {
            try
            {
                AddingPoints = false;
                AwardingAnimationOn = true;
                SlidingInInformation = true;

                //set rgb
                R = r;
                G = g;
                B = b;
                A = a;

                //reset step
                AcheivementStringStep = -20;
                PointsStringStep = Util.Cache.GraphicsDevice.Viewport.Width + 20;
                AlphaIncrementor = .01050f;
                AwardPointsAlphaValue = 0.4f;
               
                AcheivementInfo = information;
                AcheivementPoints = "";



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        #region POINTS AND REQUIREMENTS

        /// <summary>
        /// Award points to the player
        /// </summary>
        /// <param name="achievementType"></param>
        /// <param name="points"></param>
        public static void AwardPoints(Util.Helpers.PublicEnums.AcheivementType achievementType, int points)
        {
            try
            {
                DoNotAddPoints = false;
                AddingPoints = true;
                AwardingAnimationOn = true;
                SlidingInInformation = false;

                //reset step
                AcheivementStringStep = -20;
                PointsStringStep = Util.Cache.GraphicsDevice.Viewport.Width + 20;
                AlphaIncrementor = .01050f;
                AwardPointsAlphaValue = 0.4f;
                //set points to add
                PointsToAdd = points;
                //save points before awarding more
                PointsBeforeAwarding = Levels.LevelManager.CurrentMap.Points;
                //add points to the user's account
                AwardingColor = new int[] { 127, 0, 55, 255 };

                if (achievementType != Util.Helpers.PublicEnums.AcheivementType.None)
                {
                    switch (achievementType)
                    {
                        case Util.Helpers.PublicEnums.AcheivementType.AvatarHidden:
                            {


                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Well Hidden!";
                                break;
                            }

                        case Util.Helpers.PublicEnums.AcheivementType.BombDefused:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Bomb Defused!";
                                break;

                            }
                        case Util.Helpers.PublicEnums.AcheivementType.BombFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Bomb Found!";
                                break;

                            }
                        case Util.Helpers.PublicEnums.AcheivementType.LetterFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Letter Found!";
                                break;
                            }
                        case Util.Helpers.PublicEnums.AcheivementType.AllLettersFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "All letters found!";
                                break;
                            }
                    }

                    //save points and stars
                    World.StorageManager.SavePointsAndStarsForTheMap();
                }
               


            }
            catch(Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// Award points to the player
        /// </summary>
        /// <param name="achievementType"></param>
        /// <param name="points"></param>
        public static void AwardPoints(Util.Helpers.PublicEnums.AcheivementType achievementType, int points, float alphaValue)
        {
            try
            {
                DoNotAddPoints = false;
                AddingPoints = true;
                AwardingAnimationOn = true;
                SlidingInInformation = false;

                //reset step
                AcheivementStringStep = -20;
                PointsStringStep = Util.Cache.GraphicsDevice.Viewport.Width + 20;
                AlphaIncrementor = .01050f;
                AwardPointsAlphaValue = alphaValue;
                //set points to add
                PointsToAdd = points;
                //save points before awarding more
                PointsBeforeAwarding = Levels.LevelManager.CurrentMap.Points;
                //add points to the user's account
                AwardingColor = new int[] { 127, 0, 55, 255 };



                if (achievementType != Util.Helpers.PublicEnums.AcheivementType.None)
                {
                    switch (achievementType)
                    {
                        case Util.Helpers.PublicEnums.AcheivementType.AvatarHidden:
                            {


                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Well Hidden!";
                                break;
                            }

                        case Util.Helpers.PublicEnums.AcheivementType.BombDefused:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Bomb Defused!";
                                break;

                            }
                        case Util.Helpers.PublicEnums.AcheivementType.BombFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Bomb Found!";
                                break;

                            }
                        case Util.Helpers.PublicEnums.AcheivementType.LetterFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "Letter Found!";
                                break;
                            }
                        case Util.Helpers.PublicEnums.AcheivementType.AllLettersFound:
                            {
                                AcheivementPoints = "+ " + points.ToString() + " Points!";
                                AcheivementInfo = "All letters found!";
                                break;
                            }
                    }

                    //save points and stars
                    World.StorageManager.SavePointsAndStarsForTheMap();
                }




            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// Message slides in and
        /// informes user about something
        /// </summary>
        /// <param name="achievementType"></param>
        /// <param name="points"></param>
        public static void AwardMessage(string message, int value, string suffix, string prefix, int[] color,float alphaValue)
        {
            try
            {
                AddingPoints = true;
                AwardingAnimationOn = true;
                SlidingInInformation = false;
                DoNotAddPoints = true;

                //reset step
                AcheivementStringStep = -20;
                PointsStringStep = Util.Cache.GraphicsDevice.Viewport.Width + 20;
                AlphaIncrementor = .01050f;
                AwardPointsAlphaValue = alphaValue;
                AwardingColor = color;



                AcheivementPoints = suffix + " " + value.ToString() + prefix;
                AcheivementInfo = message;




            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// set warmth for each node 
        /// before the map starts
        /// </summary>
        public static void SetWarmthForEachNode()
        {

            //declare
            float[] closestBombNode = null;
            float[] closestLetterNode = null;

            try
            {
                if (Nodes != null)
                {
                    for (int i = 0; i < Nodes.Count; i++)
                    {
                        Nodes[i].Warmth = Util.Helpers.PublicEnums.NodeWarmth.None;

                        //check if this current map cell has any trackable bombs
                        if (Levels.LevelManager.CurrentMap.CurrentMapCell.HasAnyTrackableBombs)
                        {
                            //get position of closest bomb to avatar
                            closestBombNode = ScannerManager.GetClosestBomb();
                        }

                        //get closest letter node
                        closestLetterNode = ScannerManager.GetClosestLetterNode();


                        //set node's warmth
                        #region node warmth

                        //determine warmth, if not set yet
                        if (Nodes[i].Warmth == Util.Helpers.PublicEnums.NodeWarmth.None)
                        {

                            //if map cell has trackable bombs,then see what is closet ro the avatar, letter or bomb. if letter use 
                            //letter to determine warmth and color of scanner, otheriwse use the bomb
                            if (Levels.LevelManager.CurrentMap.CurrentMapCell.HasAnyTrackableBombs)
                            {
                                //if node has trackable bombs,then see if radar should show heat to the closest bomb or letter
                                if (PathFinding.CalculateH(new float[] { Nodes[i].Rectangle.X, Nodes[i].Rectangle.Y }, closestLetterNode) < PathFinding.CalculateH(new float[] { Nodes[i].Rectangle.X, Nodes[i].Rectangle.Y }, closestBombNode))
                                {
                                    //letter is closer
                                    Nodes[i].Warmth = ScannerManager.DetermineNodeWarmth(PathFinding.CalculateH(new float[] { Nodes[i].Rectangle.X, Nodes[i].Rectangle.Y }, closestLetterNode));
                                }
                                else
                                {
                                    //bomb is closer
                                    Nodes[i].Warmth = ScannerManager.DetermineNodeWarmth(PathFinding.CalculateH(new float[] { Nodes[i].Rectangle.X, Nodes[i].Rectangle.Y }, closestBombNode));
                                }

                            }
                            else
                            {
                                //first determine distance to the closest letter
                                Nodes[i].Warmth = ScannerManager.DetermineNodeWarmth(PathFinding.CalculateH(new float[] { Nodes[i].Rectangle.X, Nodes[i].Rectangle.Y }, closestLetterNode));
                            }

                        }

                        #endregion
                    }
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

       
        #endregion

        #region BREATHING BAR

        /// <summary>
        /// Create and set breathing bar rectangles
        /// </summary>
        public static void SetBreathingBars()
        {
            try
            {
                if (World.WorldManager.PauseON)
                {
                    return;
                }

                if (!BreathTimeElapsedSet)
                {
                    CurrentTimeElapsed = Util.Cache.GameTime.TotalGameTime.TotalMilliseconds;
                    BreathTimeElapsedSet = true;


                    //draw progress bars in their first state if not drawn yet
                    if (BreathProgressBar1.Width == 0 && BreathProgressBar2.Width == 0)
                    {
                        //background bar
                        BreathProgressBar1 = new Rectangle((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20, Util.Cache.Avatar.Width * 2, 20);
                        //visible bar (the one that will represent decrementing of the breath)
                        BreathProgressBar2 = new Rectangle((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20, Util.Cache.Avatar.Width * 2, 20);

                        //set breath progress bar width
                        BreathProgressBarWidth = (Util.Cache.Avatar.Width * 2);
                    }
                }
                else
                {
                    //take away breath only if full breath not taken yet
                    if (BreathProgressBar2.Width > 0)
                    {

                        //update bar's location according to current avatar's pos
                        BreathProgressBar1.Location = new Point((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20);
                        //visible bar (the one that will represent decrementing of the breath)
                        BreathProgressBar2.Location = new Point((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20);

                        //time set, so check if breath needs to be taken away
                        if (Util.Cache.GameTime.TotalGameTime.TotalMilliseconds - CurrentTimeElapsed > WorldConfig.BreathTakeawayTime)
                        {
                           
                            //modify width of bar2 (taking breath)
                            BreathProgressBar2.Width = BreathProgressBarWidth -= WorldConfig.BreathTakeawayValue;


                            //reset timer
                            BreathTimeElapsedSet = false;
                        }
                    }
                    else
                    {
                        //no more breath,just update position of rectangles according to avatar's position
                        BreathProgressBar1.Location = new Point((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20);
                        //visible bar (the one that will represent decrementing of the breath)
                        BreathProgressBar2.Location = new Point((int)Util.Cache.Avatar.CurrentPosition.X - (Util.Cache.Avatar.Width / 2), (int)Util.Cache.Avatar.CurrentPosition.Y - 20);

                        //if breath empty, start taking avatar's health
                        if (BreathProgressBar2.Width <= 0)
                        {
                            if (Util.Cache.GameTime.TotalGameTime.TotalMilliseconds - CurrentTimeElapsed > WorldConfig.BreathTakeawayTime)
                            {
                                Util.Cache.Avatar.HurtAvatar(10);
                                CurrentTimeElapsed = Util.Cache.GameTime.TotalGameTime.TotalMilliseconds;
                            }
                        }
                    }

                }

              

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        #endregion

        #region Load Config, content

        public static void LoadGameConfig()
        {
            //declare
            Stream xmlStream = null;

            try
            {
                //read config file
                //load xml file of the map
                xmlStream = TitleContainer.OpenStream("Content\\Maps\\Config.xml");
                Util.Helpers.XMLParser.LoadXML(xmlStream);
                World.WorldManager.WorldConfig = Util.Helpers.XMLParser.LoadWorldConfig();
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// Load data before
        /// loading content
        /// </summary>
        /// <param name="screen"></param>
        public static bool LoadGameData(Util.Cache.Screen screen)
        {
            try
            {
                //load data
                switch (screen)
                {
                    case Util.Cache.Screen.Menu:
                        {

                            return true;
                        }
                    case Util.Cache.Screen.Game:
                        {
                            //load avatar,textures,obstacles,items,bombs
                            //data
                            #region avatar data

                            //draw character
                            if (Util.Cache.Avatar == null)
                            {
                                Util.Cache.Avatar = new Characters.Avatar();
                                //Util.Cache.Avatar=Util.Cache.Avatar.st
                                Util.Cache.Avatar.CurrentPosition = new Vector2(Levels.LevelManager.CurrentMap.CurrentMapCell.AvatarPlacement[0].AvatarStartX, Levels.LevelManager.CurrentMap.CurrentMapCell.AvatarPlacement[0].AvatarStartY);
                                //set future position field, so it's the same as current position at the start
                                Util.Cache.Avatar.FuturePosition = Util.Cache.Avatar.CurrentPosition;

                            }

                            #endregion

                            

                            #region obstacle data

                            for (int oi = 0; oi < WorldConfig.ObstaclePlacement.Count; oi++)
                            {
                                //if the obstacle is placed on the specific map and map cell, the load
                                if (WorldConfig.ObstaclePlacement[oi].MapID == Levels.LevelManager.CurrentMap.Name && WorldConfig.ObstaclePlacement[oi].MapCellID == Levels.LevelManager.CurrentMap.CurrentMapCell.ID)
                                {
                                    Levels.LevelManager.LoadObstacle(WorldConfig.ObstaclePlacement[oi].ObstacleID);
                                }
                            }

                            //load invisible end of map obstacles
                            //Levels.LevelManager.LoadEndOfMapObstacles();

                            #endregion

                            #region items data
                            for (int ip = 0; ip < WorldConfig.ItemPlacement.Count; ip++)
                            {
                                //if the item is placed on the specific map and map cell, the load
                                if (WorldConfig.ItemPlacement[ip].MapID == Levels.LevelManager.CurrentMap.Name && WorldConfig.ItemPlacement[ip].MapCellID == Levels.LevelManager.CurrentMap.CurrentMapCell.ID)
                                {
                                    Levels.LevelManager.LoadItem(WorldConfig.ItemPlacement[ip].ItemID);
                                }
                            }
                            #endregion

                            #region bombs data

                            for (int ip = 0; ip < WorldConfig.BombPlacement.Count; ip++)
                            {
                                //if the item is placed on the specific map and map cell, the load
                                if (WorldConfig.BombPlacement[ip].MapID == Levels.LevelManager.CurrentMap.Name && WorldConfig.BombPlacement[ip].MapCellID == Levels.LevelManager.CurrentMap.CurrentMapCell.ID)
                                {
                                    Levels.LevelManager.LoadBomb(WorldConfig.BombPlacement[ip].BombID);
                                }
                            }

                            

                            #endregion

                            #region NPC
                            Levels.LevelManager.LoadNPCs();
                            #endregion

                            #region power ups

                            Levels.LevelManager.LoadPowerups();

                            #endregion

                            #region letters

                            //if secret word is null then init
                            //IT SHOULD NOT BE NULL IF INITIAL WORD DATA HAS BEEN ALREADY SAVED FOR THIS MAP 
                            if (Levels.LevelManager.CurrentMap.ChosenSecretWord == null)
                            {
                                Levels.LevelManager.CurrentMap.ChosenSecretWord = new Classes.SecretWord();
                                Levels.LevelManager.CurrentMap.ChosenSecretWord.Init();
                              
                            }

                            #endregion


                            //prepare obstacles to draw of state2
                            Levels.LevelManager.CurrentMap.CurrentMapCell.PrepareState2OfObstacles();


                            //WorldConfig.BombPlacement = null;
                            //WorldConfig.ObstaclePlacement = null;
                            //WorldConfig.NpcPlacement = null;
                            //WorldConfig.Maps = null;
                            //WorldConfig.ItemPlacement = null;
                            //WorldConfig.TexturePlacement = null;

                            return true;
                        }
                    case Util.Cache.Screen.MapSelector:
                        {
                            #region clear selected map cell
                            if (Levels.LevelManager.CurrentMap != null)
                            {
                                Levels.LevelManager.CurrentMap.CurrentMapCell = null;
                            }
                            #endregion

                            //nothing for now
                            //later:map details=open/close

                            //#region BombAfterEffects FOREACH MAP (config.MapInfos)

                            //for (int i = 0; i < WorldConfig.Maps.Count; i++)
                            //{
                            //    //SET 0 FOR NOW, LATER LOAD FROM A FILE
                            //    //file.mapCounters.ID=maps[i].ID, get defused and found counts

                            //    //bomb defused
                            //    WorldConfig.Maps[i].BombsDefusedCount = 0;
                            //    //bomb found
                            //    WorldConfig.Maps[i].BombsFoundCount = 0;
                            //}


                            //#endregion

                            //create list of map selector items in map selector class
                            Screens.MapSelector.MapSelectorItems = new List<Screens.Classes.MapSelectorItem>();

                            return true;
                        }
                    case Util.Cache.Screen.LevelSelector:
                        {
                            //OBSOLETE
                            //THIS IS NOW LOADED IN MAP SELECTOR.IS MAP CHOSEN

                            //player has chosen a map
                            //then load chosen map config
                            //load map cells
                            //and display all levels available
                            Levels.LevelManager.LoadMap(); //map config
                            Levels.LevelManager.LoadMapCells(); //map cells
                           
                            //create level selector item in level selector
                            Screens.LevelSelector.Items = new List<Screens.Classes.LevelSelectorItem>();

                            return true;
                        }
                    case Util.Cache.Screen.GameOver:
                        {
                            return true;
                        }
                    case Util.Cache.Screen.Options:
                        {
                            return true;
                        }
                    case Util.Cache.Screen.ResumedGame:
                        {
                            World.WorldManager.PauseON = false;
                            Util.Cache.PreviousScreen = Util.Cache.CurrentScreen;
                            Util.Cache.CurrentScreen = Util.Cache.Screen.Game;

                            return false; //return false so cache.SetScreen is canceled after this method (we want Game to bne current screen not ResumedGame)
                        }

                }


                return true;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }

        }



        /// <summary>
        /// load game content
        /// based on a current screen and required resources
        /// </summary>
        public static void LoadContent(Util.Cache.Screen screen)
        {
            try
            {

                //if list containing all textures is null, then throw an exception
                if (Util.Cache.Textures == null)
                {
                    throw new Exception("Textures collection is NULL");
                }
                

                //load textures:
                switch (screen)
                {
                    case Util.Cache.Screen.Menu:
                        {
                            //Util.Cache.AddTexture(this.Content.Load<Texture2D>(@"Screens\Menu"), "MainMenuScreenOld");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\OperationSneakPeekMenu"), "MainMenuScreen");
                            break;
                        }
                    case Util.Cache.Screen.Game:
                        {
                            //unload all content except global
                            //UnloadContentAndLoadGlobals();
                            LoadGlobalContent();

                            #region textures

                            for (int t = 0; t < Levels.LevelManager.CurrentMap.CurrentMapCell.TexturesToDraw.Count; t++)
                            {
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Ground\" + Levels.LevelManager.CurrentMap.CurrentMapCell.TexturesToDraw[t].Texture), Levels.LevelManager.CurrentMap.CurrentMapCell.TexturesToDraw[t].Texture);
                            }
                            

                            #endregion

                            #region obstacles

                            for (int o = 0; o < Levels.LevelManager.CurrentMap.AvailableObstacles.Count; o++)
                            {
                                //skip end of map obstacles
                                //if (Levels.LevelManager.CurrentMap.AvailableObstacles[o].ID.Contains("EndOfMap"))
                                //{ continue; }

                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Obstacles\" + Levels.LevelManager.CurrentMap.AvailableObstacles[o].TextureName), Levels.LevelManager.CurrentMap.AvailableObstacles[o].TextureName);

                            }

                            #endregion

                            #region items

                            for (int i = 0; i < Levels.LevelManager.CurrentMap.AvailableItems.Count; i++)
                            {
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Items\" + Levels.LevelManager.CurrentMap.AvailableItems[i].TextureName), Levels.LevelManager.CurrentMap.AvailableItems[i].TextureName);

                             
                            }


                            #endregion

                            #region avatar

                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charIdleFront"), "charIdleFront");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charIdleRight"), "charIdleRight");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charIdleUp"), "charIdleUp");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLeft"), "charIdleLeft");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLeft1"), "charGoLeft1");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLeft2"), "charGoLeft2");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharRight1"), "charGoRight1");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharRight2"), "charGoRight2");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkDown"), "charWalkDown1");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkDown1"), "charWalkDown2");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkUp"), "charWalkUp1");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkUp1"), "charWalkUp2");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\avatarHurt1"), "avatarHurt1");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\diveHurt"), "diveHurt");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLayDown"), "charLayDownUp");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLayDownDown"), "charLayDown");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLayRight"), "charLayDownRight");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\CharLayLeft"), "charLayDownLeft");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\avatarUnderWater"), "diveUp");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\diveDown"), "diveDown");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\diveLeft"), "diveLeft");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\diveRight"), "diveRight");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkCrossDownLeft"), "charWalkCrossDownLeft");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkCrossDownRight"), "charWalkCrossDownRight");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkCrossUpLeft"), "charWalkCrossUpLeft");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\charWalkCrossUpRight"), "charWalkCrossUpRight");

                            #endregion

                            #region npc

                            for (int i = 0; i < Levels.LevelManager.CurrentMap.NPCs.Count; i++)
                            {
                                for(int i1=0;i1<Levels.LevelManager.CurrentMap.NPCs[i].Textures.Count;i1++)
                                {
                                    Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\NPC\" + Levels.LevelManager.CurrentMap.NPCs[i].Textures[i1].ID), Levels.LevelManager.CurrentMap.NPCs[i].Textures[i1].ID);
                                }
                            }

                            //fov circle
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\NPC\circleView"), "circleView");
                            //npc distracted icon
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Characters\NPC\NpcDistractedIcon"), "NpcDistractedIcon");

                            #endregion

                            #region bombs

                            for (int i = 0; i < Levels.LevelManager.CurrentMap.AvailableBombs.Count; i++)
                            {
                                //active
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\" + Levels.LevelManager.CurrentMap.AvailableBombs[i].Texture), Levels.LevelManager.CurrentMap.AvailableBombs[i].Texture);
                                //inactive
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\" + Levels.LevelManager.CurrentMap.AvailableBombs[i].TextureInactive), Levels.LevelManager.CurrentMap.AvailableBombs[i].TextureInactive);
                                //defused, 27.02.2013 currently defused bombs are not being drawn
                                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\" + Levels.LevelManager.CurrentMap.AvailableBombs[i].TextureDefused), Levels.LevelManager.CurrentMap.AvailableBombs[i].TextureDefused);

                              //temp explosion texture
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\bombExplosionTemp"), "bombExplosionTemp");

                                #region wires
                                //wires for that bomb
                                for (int i1 = 0; i1 < LevelManager.CurrentMap.AvailableBombs[i].Wires.Count; i1++)
                                {
                                    Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\Wires\" + LevelManager.CurrentMap.AvailableBombs[i].Wires[i1].Texture), LevelManager.CurrentMap.AvailableBombs[i].Wires[i1].Texture);
                                }

                                //empty slot
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\Wires\WireSlotEmpty"), "WireSlotEmpty");
                                //bomb locked,unlocked
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\Lock"), "BombLocked");
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Bombs\unlock"), "BombUnlocked");

                                #endregion

                            }

                            #endregion

                           

                            #region power ups
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"PowerUps\powerUpHUD"), "PowerUpHUD");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"PowerUps\PowerUpSlot"), "powerUpEmptySlot");
                            #endregion

                            #region avatar move pattern
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\XMark"), "XMark");
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\Dot"), "Dot");

                            #endregion

                            //game over screen
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\gameOver"), "gameOver");


                            break;
                        }
                    case Util.Cache.Screen.MapSelector:
                        {
                            //load map icons
                            //->foreach map from config (map\icon\.png)
                            for (int mi = 0; mi < World.WorldManager.WorldConfig.Maps.Count; mi++)
                            {
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Maps\" + World.WorldManager.WorldConfig.Maps[mi].ID + @"\Icon\MapIcon"), World.WorldManager.WorldConfig.Maps[mi].ID + "_MapIcon");
                                
                            }

                            //load map selector frames
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\MapSelector\MapSelect"),"MapSelectorFrame");

                            

                            break;
                        }
                    case Util.Cache.Screen.LevelSelector:
                        {
                            //load map cell icons
                            for (int mci = 0; mci < LevelManager.CurrentMap.MapCells.Count; mci++)
                            {
                                //icon
                                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Maps\" + LevelManager.CurrentMap.Name + @"\Parts\Icons\" + LevelManager.CurrentMap.MapCells[mci].ID+"Icon"), LevelManager.CurrentMap.MapCells[mci].ID+"_Icon");
                                

                            }

                            //load background
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Maps\" + LevelManager.CurrentMap.Name + @"\LevelSelectorBackground\LevelSelectorBackground"), "LevelSelectorBackground");

                            //load map cell selector frame
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\LevelSelector\MapCellSelect"), "LevelSelectorFrame");


                            break;
                        }
                    case Util.Cache.Screen.LoadMap:
                        {
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\LoadingScreen\loadingScreen"), "LoadingScreen");

                            break;
                        }
                    case Util.Cache.Screen.Pause:
                        {
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\PauseScreen"), "PauseScreen");
                            break;
                        }
                    case Util.Cache.Screen.Options:
                        {
                            break;
                        }
                    case Util.Cache.Screen.Store:
                        {
                            Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\StoreMockup"), "StoreMockup");
                            break;
                        }

                }

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }


        /// <summary>
        /// Load global content
        /// </summary>
        public static void LoadGlobalContent()
        {
            try
            {
                //load global content here
                if (Util.Cache.Textures != null)
                {
                    return;
                }


                Util.Cache.Textures = new List<Util.Classes.Texture>();

                #region load popups
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Popups\ErrorPopup"), "errorPopup");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Popups\popup1"), "MessageBox");
                #endregion

                #region Load world/global items
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Buttons\Button"), "button1");
                #endregion

                #region splash screen
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\SplashScreen\splashScreen"), "splashScreen1");
                #endregion

                #region loading screen
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"Screens\LoadingScreen\loadingScreen"), "loadingScreen");

                #endregion


                #region fonts
                Util.Cache.Fonts = new List<Util.Classes.Font>();

                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\TitleFont"), "default");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\SmallFont"), "small");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\HUDScoreFont"), "HUDScore");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\AwardPointsFont"), "AwardPointsFont");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\StencilFont"), "StencilFont");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\LargeBlackFont"), "LargeBlackFont");
                Util.Cache.AddFont(Util.Cache.ContManager.Load<SpriteFont>(@"Fonts\VerySmallFont"), "VerySmallFont");
                #endregion

                #region World
                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\pad"), "HUDPad");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\actionACtion"), "HUDActionIcon");
                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\actionHand"), "HUDActionHand");
                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\foodIcon"), "HUDFood");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\EmptySlot"), "HUDEmptySlot");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\EmptySlotActivated"), "HUDEmptySlotActivated");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\EnergyFullIcon"), "HUDEnergyFull");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\heartHalfFull"), "HUDHeartHalfFull");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\heartFulll"), "HUDHeartFull");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\inventory"), "HUDInventory");
                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\nextPart"), "HUDNextPart");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\actionACtionHighlighted"), "HUDActionIconHighlighted");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\actionHandHighlighted"), "HUDActionHandHighlighted");
               // Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\inventoryHighlighted"), "HUDInventoryHighlighted");
                //Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\ArmedFist"), "HUDArmedFist");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\Crouch"), "HUDCrouch");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\layDown"), "HUDLayDown");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\nextPart"), "HUDNextPart");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\nextPartEndOfMap"), "HUDNextPartEndOfMap");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\run"), "HUDRun");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\stand"), "HUDStand");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\walk"), "HUDWalk");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\interactionIconDisabled"), "interactionIconDisabled");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\interactionIconEnabled"), "interactionIconEnabled");
                //field of view
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewDanger"), "fieldOfViewDanger");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewDangerRight"), "fieldOfViewDangerRight");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewDangerLeft"), "fieldOfViewDangerLeft");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewNetural"), "fieldOfViewNeutral");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewNeturalRight"), "fieldOfViewNeutralRight");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\fieldOfViewNeturalLeft"), "fieldOfViewNeutralLeft");
                //misc
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\protectionUmbrella"), "HUDprotectionUmbrella");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\heat"), "heat");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\heat1"), "heat1");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\heatWithoutFrame"), "heat3");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\greyedOutBackground"), "greyedOutBackground");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\actionArea"), "actionArea");

                //progress bars
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\progressBar"), "progressBar1");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\progressBar2"), "progressBar2");
                //inventory
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\inventorySlot"), "inventorySlot");
                //arrows
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\ArrowDown"), "ArrowDown");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\ArrowLeft"), "ArrowLeft");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\ArrowRight"), "ArrowRight");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\ArrowUp"), "ArrowUp");
                //stars
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\MapStars"), "MapStars");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\MapStars1"), "MapStars1");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\MapStars2"), "MapStars2");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"HUD\MapStars3"), "MapStars3");

                //pointers
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\RedPointerRight"), "RedPointerRight");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\RedPointerLeft"), "RedPointerLeft");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\RedPointerUp"), "RedPointerUp");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\RedPointerDown"), "RedPointerDown");

                //debug rectangle
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\emptyRect"), "EmptyRect");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\emptyRect2"), "EmptyRect2");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\redRect"), "redRect");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"World\yellowRect"), "yellowRect");


                #endregion


                #region bomb scanner
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\SelectedScannerNode"), "SelectedScannerNode");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UNSelectedScannerNode"), "UNSelectedScannerNode");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame1");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame2");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame3");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame4");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame5");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\UncoverBombAnimationFrame1"), "UncoverBombAnimationFrame6");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BombScanner"), "BombScanner");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BombMap"), "BombMap");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodePhase1"), "ScannerNodePhase1");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodePhase2"), "ScannerNodePhase2");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScanButton"), "ScanButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\DisabledNode"), "DisabledNode");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\AutoScannerOFF"), "AutoScannerOFF");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\AutoScannerON"), "AutoScannerON");

                //colors
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodeVeryCold"), "ScannerNodeVeryCold");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodeCold"), "ScannerNodeCold");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodeWarm"), "ScannerNodeWarm");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodeHot"), "ScannerNodeHot");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\ScannerNodeVeryHot"), "ScannerNodeVeryHot");


                #region energy bar
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar0P"), "0P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar5P"), "5P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar10P"), "10P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar15P"), "15P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar20P"), "20P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar25P"), "25P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar30P"), "30P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar35P"), "35P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar40P"), "40P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar45P"), "45P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar50P"), "50P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar55P"), "55P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar60P"), "60P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar65P"), "65P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar70P"), "70P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar75P"), "75P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar80P"), "80P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar85P"), "85P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar90P"), "90P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar95P"), "95P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\EnergyBar\EnergyBar100P"), "100P");
                #endregion

                #region battery energy bar
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar0P"), "BatteryBar0P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar5P"), "BatteryBar5P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar10P"), "BatteryBar10P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar15P"), "BatteryBar15P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar20P"), "BatteryBar20P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar25P"), "BatteryBar25P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar30P"), "BatteryBar30P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar35P"), "BatteryBar35P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar40P"), "BatteryBar40P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar45P"), "BatteryBar45P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar50P"), "BatteryBar50P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar55P"), "BatteryBar55P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar60P"), "BatteryBar60P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar65P"), "BatteryBar65P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar70P"), "BatteryBar70P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar75P"), "BatteryBar75P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar80P"), "BatteryBar80P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar85P"), "BatteryBar85P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar90P"), "BatteryBar90P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar95P"), "BatteryBar95P");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"BombScanner\BatteryLevelBar\BatteryBar100P"), "BatteryBar100P");
                #endregion

                #endregion

                #region bomb map

                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\CancelButton"), "ContextMenuCancelButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\GreenMarker"), "GreenMarker");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\GreenMarkerButton"), "GreenMarkerButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\OrangeMarker"), "OrangeMarker");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\OrangeMarkerButton"), "OrangeMarkerButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\ExitButton"), "ExitButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\RedMarker"), "RedMarker");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\RedMarkerButton"), "RedMarkerButton");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\ScannerMap"), "ScannerMap");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\AvatarNode"), "AvatarNode");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\GreyBackground"), "GreyBackground");
                Util.Cache.AddTexture(Util.Cache.ContManager.Load<Texture2D>(@"MapScanner\SkyBackground"), "SkyBackground");
                #endregion

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Unload content
        /// </summary>
        /// <param name="screen"></param>
        public static void UnloadContent()
        {
            try
            {

                Util.Cache.ContManager.Unload();
            
                //clear textures&content from cache:
                Util.Cache.Textures = null;
                Util.Cache.Fonts = null;
                


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// Unload content
        /// but load global content immediately after that
        /// </summary>
        /// <param name="screen"></param>
        public static void UnloadContentAndLoadGlobals()
        {
            try
            {

                Util.Cache.ContManager.Unload();
                //clear textures&content from cache:
                Util.Cache.Textures = null;
                Util.Cache.Fonts = null;

                //load global
                LoadGlobalContent();

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }



        #endregion

        #region SAVING

      

        /// <summary>
        /// Save bomb tries
        /// </summary>
        /// <param name="bombName"></param>
        /// <param name="tries"></param>
        public static void SaveBombTries(string bombName, int tries)
        {
            //declare
            Util.Classes.BombToDraw btd = null;

            try
            {

                btd = Levels.LevelManager.GetBombToDrawByName(World.WorldManager.BombInstanceBeingDefused.Name);

                btd.Tries = tries;

                btd = null;

                StorageManager.SaveWorldInfo();


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        #endregion
        /// <summary>
        /// Bomb explosion
        /// </summary>
        public static void MakeAnExplosion()
        {
            try
            {
                //temp:
                Util.Cache.Draw(Util.Cache.GetTexture("bombExplosionTemp").Text2D, new Rectangle(0, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height), Color.White);
                Thread.Sleep(8);
                Util.Cache.SetCurrentScreen(Util.Cache.Screen.GameOver);



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// Make interaction between item and obstacle happen
        /// </summary>
        /// <param name="obstacle"></param>
        /// <param name="item"></param>
        public static void ItemInteractsWithObstacle(Util.Classes.ObstacleToDraw obstacle, Util.Classes.Item item)
        {
            try
            {
                //dispose of tool icon next to obstacle to draw
                obstacle.ToolIcon = null;
                obstacle.Interactive = false;
               

                //2. set current state to 2 for the obstacle  so from now on, there is only a second state of the obstacle now
                obstacle.CurrentState = 1;
                obstacle.ObstacleID = obstacle.ItemState2;//change names,ex: fallen tree becomes fallen tree cut
                ///get rid of obstacle state 2
                obstacle.ItemState2 = null;
                obstacle.State2Obstacle = null;
                obstacle.HasState2=false;
                obstacle.TextureSet = false;

                //get new texture name and new walkable property as this will be a different obstacle now
                for (int i = 0; i < Levels.LevelManager.CurrentMap.AvailableObstacles.Count; i++)
                {
                    if (Levels.LevelManager.CurrentMap.AvailableObstacles[i].ID == obstacle.ObstacleID)
                    {
                        obstacle.Walkable = Levels.LevelManager.CurrentMap.AvailableObstacles[i].Walkable;
                        obstacle.TextureName = Levels.LevelManager.CurrentMap.AvailableObstacles[i].TextureName;
                        break;

                    }
                }


                //remove item from the inventory (if items is not null)
                if (item != null)
                {
                    RemoveFromInventory(item);
                }

                //re validate nodes (re check walkable/non walkable nodes)
                PathFinding.CheckIfNodesAreWalkable();

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }


        /// <summary>
        /// See if rectangle is outside the screen boundries
        /// at any point
        /// left screen boundry
        /// or right screen boundryh
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public static bool IsRectangleOutsideTheScreenLeftRight(Rectangle rect)
        {
            try
            {
                //left boundry:
                if (Util.Cache.GraphicsDevice.Viewport.Width - rect.X < rect.Width)
                {
                    //rectangle does not fit the screen boundries
                    return true;
                }

                //OR:
                //right boundry
                if (rect.X < Util.Cache.GraphicsDevice.Viewport.X)
                {
                    return true;
                }



                return false;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }


        }

        #region movement

        ///// <summary>
        ///// check if a point A is touching any of the objets in the world
        ///// </summary>
        ///// <returns></returns>
        //public static bool IsAnyObjectTouched(Vector2 point, int width, int height)
        //{


        //    try
        //    {
        //        #region obstacles
        //        //declare
        //        Util.Classes.Obstacle o;

        //        if (Levels.LevelManager.CurrentMap.CurrentMapCell.Obstacles != null)
        //        {
        //            if (Levels.LevelManager.CurrentMap.CurrentMapCell.Obstacles.Count > 0)
        //            {
        //                for (int i = 0; i < Levels.LevelManager.CurrentMap.CurrentMapCell.Obstacles.Count; i++)
        //                {
        //                    //get obstacle's instance
        //                    o = Levels.LevelManager.GetObstacleByName(Levels.LevelManager.CurrentMap.CurrentMapCell.Obstacles[i].ObstacleID);

        //                    //if obstacle is touched, return true
        //                    if (o.IsObstacleTouched(Levels.LevelManager.CurrentMap.CurrentMapCell.Obstacles[i].Position, point, width, height) && (!o.IsWater && !o.Walkable))
        //                    {
        //                        return true;
        //                    }
        //                }
        //            }
        //        }


        //        #endregion



        //        return false;

        //    }
        //    catch (Exception ex)
        //    {
        //        Util.ErrorLogging.LogError(ex);
        //        return false;
        //    }
        //}


        /// <summary>
        /// if obstacle is touched, return true
        /// if obstacle is touched and it can harm avatar, harm avatar
        /// </summary>
        /// <returns></returns>
        public static bool IsObstacleTouched(int[] obstacle, int[] rectangleToCompare)
        {

            try
            {
                //THIS ONE IS BEING USED
                //26,03,2013

                //see if this.location overlaps with cache.avatar.location

                //if yes, if obstacle is harmful, then harm avatar
                //by calling avatar.MakeHarm(int hpToTakeAway) (it plays harm animation and deducts life points)

           

                //draw help rectangles
                Rectangle avatarRect = new Rectangle(rectangleToCompare[0], rectangleToCompare[1], rectangleToCompare[2], rectangleToCompare[3]);
                //Rectangle obstacleRect = new Rectangle((int)ObstaclePos.X+OffsetLeft, (int)ObstaclePos.Y+OffsetUp, this.Width-OffsetRight-OffsetLeft, this.Height-OffsetDown-OffsetUp);
                Rectangle obstacleRect = new Rectangle(obstacle[0], obstacle[1], obstacle[2], obstacle[3]);

                //see if touching
                if (obstacleRect.Intersects(avatarRect))
                {
                    return true;
                }




                return false;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }


        }


        #endregion


       

        #region bomb

        /// <summary>
        /// Check if avatar is currently defusing hte bomb
        /// if yes, then handle it
        /// IF user tapped on bomb, then yes
        /// </summary>
        public static void IsAvatarDefusingBomb(Vector2 tapPos)
        {
            try
            {
                //see if user tapped on any of the bombs
                for (int i = 0; i < LevelManager.CurrentMap.CurrentMapCell.Bombs.Count; i++)
                {
                    if ((tapPos.X > LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Position.X && tapPos.X < LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Position.X + LevelManager.CurrentMap.CurrentMapCell.Bombs[i].GetBombWidth()) && (tapPos.Y > LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Position.Y && tapPos.Y < LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Position.Y + LevelManager.CurrentMap.CurrentMapCell.Bombs[i].GetBombHeight()))
                    {


                        #region if clicked on defused bomb,or bomb is hidden and has MustBeVisibleToDfeuse set to true then do nothing

                        //if bomb already defused, then return
                        if (LevelManager.CurrentMap.BombDefused || LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Defused || (LevelManager.CurrentMap.CurrentMapCell.Bombs[i].IsHidden && LevelManager.CurrentMap.CurrentMapCell.Bombs[i].MustBeVisbleToDefuse))
                        {
                            //before there was also LevelManager.CurrentMap.CurrentMapCell.Bombs[i].defused but not working with it anymore, maybe that flag is not assigned anywhere to true?
                   
                            return;
                        }

                        //if avatar is too far from bomb, then tell user and return
                        if (!LevelManager.CurrentMap.CurrentMapCell.Bombs[i].AvatarNearTheBomb)
                        {
                            //Util.MessageBox.ShowMessage("You must get close to the bomb to defuse it!");
                            return;
                        }

                        //if user has 0 tries fro the bomb,let user know and do nothing.
                        //player probably used cancel button 3 times
                        if (LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Tries <= 0)
                        {
                            Util.MessageBox.ShowMessage("You have no more attempts for this bomb!");
                            return;
                        }

                        #endregion

                        #region check if secret word is solved (all letters collected)

                        //if secret word not solved, then show keyboard and let user guess the password
                        if (!LevelManager.CurrentMap.ChosenSecretWord.Solved)
                        {
                            //if pass not guessed, then return
                            LevelManager.CurrentMap.ChosenSecretWord.GuessThePassword();

                            //if still secret word not solved, then return
                            if (!LevelManager.CurrentMap.ChosenSecretWord.Solved)
                            {
                                return;
                            }
                        }


                        #endregion


                        //bomb clicked
                        IsDefusingBomb = true;
                        //set ID
                        BombBeingDefused = LevelManager.CurrentMap.CurrentMapCell.Bombs[i].BombID;

                        //get instance of the bomb being defused
                        for (int bombI = 0; bombI < Levels.LevelManager.CurrentMap.AvailableBombs.Count; bombI++)
                        {
                            //see which bomb has been tapped on, to defuse
                            if (Levels.LevelManager.CurrentMap.AvailableBombs[bombI].Name.ToLower() == World.WorldManager.BombBeingDefused.ToLower())
                            {
                                BombInstanceBeingDefused = Levels.LevelManager.CurrentMap.AvailableBombs[bombI];
                                break;
                            }
                        }


                        BombHandler.DrawBombHeat = true;

                        //reset defusing wire time grace
                        ElapsedDefusingWireGracePeriod = -1;
                        BombHandler.PrepCompleted = false;
                        BombHandler.StartShuffle = false;
                        BombHandler.CoverWires = false;
                        BombHandler.ShuffleDone = false;
                        //set attempts from bom to draw instance
                        BombHandler.NumberOfAttempts = LevelManager.CurrentMap.CurrentMapCell.Bombs[i].Tries;
                        TimeSubtracted = false;
                    }
                }
                

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }


        #endregion


        #region controlling

        /// <summary>
        /// Initilize all maps
        /// </summary>
        public static void InitAllMaps()
        {
            try
            {
                ///call init maps that is in the level manager
                LevelManager.InitMaps();

                

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion

        #region drawing

        /// <summary>
        /// Draw level
        /// </summary>
        public static void DrawLevel()
        {
            try
            {
                //call Draw of the level manager
                Levels.LevelManager.DrawMap();



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Draw HUD
        /// </summary>
        public static void DrawHUD()
        {
            try
            {
                //do not draw HUD if inventory is opened
                if (IsAvatarActionMenuOpen)
                {
                    return;
                }
                

                    //draw bottom hud
                    //control pad
                    //Util.Cache.Draw(Util.Cache.GetTexture("HUDPad").Text2D, new Rectangle(625, 330, 165, 165), Color.White);



                    ////tool/weapon slot
                    //Util.Cache.Draw(Util.Cache.GetTexture("HUDArmedFist").Text2D, new Rectangle(705, 95, 60, 60), Color.White);


                    ////tool/weapon slot
                    //Util.Cache.Draw(Util.Cache.GetTexture("HUDArmedFist").Text2D, new Rectangle(35, 95, 60, 60), Color.White);

                    ////hearts(lives) (4)
                if (Util.Cache.Avatar.IsBeingHurt)
                {
                    Util.Cache.Draw(Util.Cache.GetTexture("HUDHeartFull").Text2D, new Rectangle(625, 20, 30, 30), Color.White);
                    Util.Cache.Draw(Util.Cache.GetTexture("HUDHeartFull").Text2D, new Rectangle(660, 20, 30, 30), Color.White);
                    Util.Cache.Draw(Util.Cache.GetTexture("HUDHeartFull").Text2D, new Rectangle(695, 20, 30, 30), Color.White);
                }
                   

                    //points && HP info (hp info-temp)
                    if (!PointsAdded)
                    {
                        //if points are still less than they;re suposed to be
                        //then add the difference

                        Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, Levels.LevelManager.CurrentMap.Points.ToString() + " Points", new Vector2(Util.Cache.GraphicsDevice.Viewport.Width / 2, 20), 45, Color.LightBlue);

                        //hp
                        Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, "HP:"+Util.Cache.Avatar.Health.ToString(), new Vector2((Util.Cache.GraphicsDevice.Viewport.Width / 2)-130, 20), 45, Color.Red);
                    }
                    else
                    {

                        //points regular
                        Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, Levels.LevelManager.CurrentMap.Points.ToString() + " Points", new Vector2(Util.Cache.GraphicsDevice.Viewport.Width / 2, 20), 45, Color.Gold);
                        //+ x points text under the regular points
                        Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, "+ " + PointsToAdd.ToString(), new Vector2(Util.Cache.GraphicsDevice.Viewport.Width / 2, 70), 45, Color.Red);
                    }
                


                ////time left (DRAWN ALWAYS, even when bomb is being defused
                ////Util.Cache.Draw(Util.Cache.GetTexture("HUDNoise").Text2D, new Rectangle(65, 20, 100,35), Color.White);
                //if (TimeSubtracted)
                //{
                //    //draw in red...
                //    Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, MinutesLeft.ToString() + ":" + SecondsLeft.ToString(), new Vector2(65, 20), 45, Color.Red);
                //}
                //else
                //{
                //    //draw in black
                //    Util.Cache.DrawString(Util.Cache.GetFont("HUDScore").FontFace, MinutesLeft.ToString() + ":" + SecondsLeft.ToString(), new Vector2(65, 20), 45, Color.Black);
                //}

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                
                return;
            }
        }


        /// <summary>
        /// when the bomb is being defused draw the timer
        /// </summary>
        public static void DrawTimerInHeat()
        {
            try
            {
                //draw in black
                Util.Cache.DrawString(Util.Cache.GetFont("LargeBlackFont").FontFace, MinutesLeft.ToString() + ":" + SecondsLeft.ToString(), new Vector2(((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - 60, ((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - 200), 45, Color.Black);

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// draw aarding points for acheivement
        /// </summary>
        public static void DrawAwardingPoints()
        {
            try
            {
               
                    Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, AcheivementInfo, new Vector2(AcheivementStringStep, Util.Cache.GraphicsDevice.Viewport.Height / 2), 60, Color.Lerp(new Color(AwardingColor[0], AwardingColor[1], AwardingColor[2], AwardingColor[3]), Color.Transparent, AwardPointsAlphaValue));
                    Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, AcheivementPoints, new Vector2(PointsStringStep, (Util.Cache.GraphicsDevice.Viewport.Height / 2) + 70), 60, Color.Lerp(new Color(AwardingColor[0], AwardingColor[1], AwardingColor[2], AwardingColor[3]), Color.Transparent, AwardPointsAlphaValue));
                



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);

                return;
            }


        }


        /// <summary>
        /// draw sliding in information
        /// </summary>
        public static void DrawSlidingInInfo()
        {
            try
            {

                Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, AcheivementInfo, new Vector2(AcheivementStringStep, Util.Cache.GraphicsDevice.Viewport.Height / 2), 60, Color.Lerp(new Color(R,G,B,A), Color.Transparent, AwardPointsAlphaValue));
              
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);

                return;
            }


        }

        #region ITEM USING

        /// <summary>
        /// draw field of reach
        /// </summary>
        public static void DrawThrowFieldOfReach()
        {
            try
            {
                //draw throw field of reach
                if (DrawThrowFieldOfReachFlag)
                {

                    if (!ThrowComplete)
                    {
                        Util.Cache.Draw(Util.Cache.GetTexture("actionArea").Text2D, FieldOfThrowReachRect, Color.White);
                        ThrowFieldOfReachReady = true;
                    }

                    //if throw has been made, draw the bottle
                    #region draw the thrown object
                    //animation control here

                    //the objects lands
                  if (ThrowPosition.X > 0)
                  {

                      #region item lands and breaks and makes noise
                      //draw item state 2 -get item by its name; it's name is in itemState2 property of the thrown item
                      Util.Cache.Draw(Util.Cache.GetTexture(LevelManager.GetItemByName(ThrownItem.ItemState2).Name).Text2D, new Rectangle((int)ThrowPosition.X, (int)ThrowPosition.Y, (int)ThrownItem.Width, (int)ThrownItem.Height), Color.White);


                      //set throw complete to true
                      ThrowComplete = true;
                      //set ThrowDir arrows drawn to false, as direction arrows are not drawn anymore at that point
                      Util.Cache.Avatar.ThrowDirectionArrowsDrawn = false;

                      //save current time (only if not yet set
                      if (CurrentElapsedTimeUponThrowComplete <= 0)
                      {
                          CurrentElapsedTimeUponThrowComplete = Util.Cache.GameTime.TotalGameTime.TotalMilliseconds;
                      }

                      //exit throwing mode after x seconds
                      if (Util.Cache.GameTime.TotalGameTime.TotalMilliseconds - CurrentElapsedTimeUponThrowComplete >= 3000)
                      {
                          ExitThrowingMode();
                      }

                      #endregion

                  }


                  

                    #endregion
                }

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// make a throw
        /// when user tapped on screen and 
        /// chose where to throw
        /// </summary>
        /// <param name="tapPos"></param>
        public static void MakeAThrow(Vector2 tapPos)
        {
            //declare
            bool npcTapped = false;

            try
            {
                //cannot throw if:throw is already in progress, heat is active
                if (DrawThrowFieldOfReachFlag && ThrowFieldOfReachReady && (!ThrownItem.ThrowInProgress) && (!IsHeatActive) && ThrowDirectionChosen)
                {
                    //first determine if user tapped within field of throw 
                    if ((tapPos.X >= FieldOfThrowReachRect.X && tapPos.X <= FieldOfThrowReachRect.X + FieldOfThrowReachRect.Width) && (tapPos.Y >= FieldOfThrowReachRect.Y && tapPos.Y <= FieldOfThrowReachRect.Y + FieldOfThrowReachRect.Height))
                    {
                        //save the tap pos, only if valid (cannot throw where the opponent stands)
                        //if (NPCToDistract != null)
                        //{
                        //    for (int i = 0; i < NPCToDistract.Count; i++)
                        //    {
                        //        #region check if player tapped on npc 

                        //        #endregion
                        //    }
                        //}

                        ThrowPosition = tapPos;
                        ThrownItem.ThrowInProgress = true;
                        

                    }
                    else
                    {
                        //clsoe throwing mode
                        ExitThrowingMode();
                    }
                }
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// make a progress in a throw,
        /// move the item away from avatar towards the destination
        /// </summary>
        public static void MakeProgressInThrow()
        {
            try
            {
                if (ThrownItem == null)
                {
                    return;
                }

                if (ThrownItem.ThrowInProgress)
                {

                    #region determine direction of the throw






                    #endregion


                    //GetObstacleToDrawByName(ThrownItem).Position

                    //set avatar to the throwing position
                    //Util.Cache.Avatar.SetState(Characters.Avatar.States.ThrowLeft);

                    if (ThrowComplete)
                    {
                        //not drawn anymore at this point
                        ThrowFieldOfReachReady = false;

                        //distract npcs
                        if (NPCToDistract != null)
                        {
                            for (int i = 0; i < NPCToDistract.Count; i++)
                            {
                                if (!NPCToDistract[i].IsDistracting)
                                {
                                    NPCToDistract[i].Distract();
                                }
                            }
                        }
                    }


                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// exit throwing mode
        /// </summary>
        public static void ExitThrowingMode()
        {
            try
            {
                //if player tapped outside the throw field of reach
                //then close it
                if (ThrownItem != null)
                {
                    DrawThrowFieldOfReachFlag = false;
                    ThrowFieldOfReachReady = false;
                    ThrownItem.ThrowInProgress = false;
                    ThrowDirectionChosen = false;
                    ThrowPosition = new Vector2(-1, -1);
                    CurrentElapsedTimeUponThrowComplete = -1;

                    //remove from the inventory,only if throw has been completed
                    //(throw can be also exited without completing it)
                    if (ThrowComplete)
                    {
                        RemoveFromInventory(ThrownItem);
                    }

                    ThrowComplete = false;
                    //remove control rect around the NPCs
                    if (NPCToDistract != null)
                    {
                        for (int i = 0; i < NPCToDistract.Count; i++)
                        {
                            NPCToDistract[i].ClearDistractionControl();
                        }
                    }

                    //clear npc list
                    NPCToDistract = null;
                    //StoredFOVs = null;
                   
                    //dispose of chosen throw direction
                    ThrownItem.ThrowDirection = Util.Helpers.PublicEnums.ItemMoveDirection.None;
                    ThrownItem = null;

                    Util.Cache.Avatar.DisposeThrowArrows();
                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        #endregion

        /// <summary>
        /// clear game world vars
        /// </summary>
        public static void ClearGameWorld()
        {
            try
            {
                Nodes = null;
                HeatRectangle = null;
                World.WorldManager.IsHeatActive = false;

                World.ScannerManager.BatteryLevel = 100;
                World.ScannerManager.Energy = 100;
                World.ScannerManager.ExitChooseNodesMode();
                World.ScannerManager.AutoScannerON = false;
                Util.Cache.Avatar = null;
                Inventory = new List<Util.Classes.InventoryItem>();
                InventoryClosed = true;
                InventorySlots = new List<Util.Classes.InventorySlot>();
                Util.Cache.ProcessedNodes = new List<Classes.ScannerNode>();

                LevelManager.CurrentMap = new Map();
                LevelManager.AvailableMaps = new List<Map>();

                BombHandler.ResetBombFields();


                //Levels.LevelManager.CurrentMap.LettersFound = 0;
                //Levels.LevelManager.CurrentMap.ChosenSecretWord = null;
                //Levels.LevelManager.CurrentMap.WildPasswordGuesses = 3;
                //Levels.LevelManager.CurrentMap.Points = 0;
                //Levels.LevelManager.CurrentMap.BombDefused = false;
                //Levels.LevelManager.CurrentMap.


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #region INVENTORY

        /// <summary>
        /// Close the inventory
        /// </summary>
        public static void CloseTheInventory()
        {
            try
            {
                IsAvatarActionMenuOpen = false;
                //pause off
                PauseON = false;

                //reset slot positions
                OddSlotPos = new Vector2(0, 0);
                EvenSlotPos = new Vector2(0, 0);
                //disapose of inventory slots collection
                InventorySlots = null;
                BombScanner = null;
                ScannerMap = null;


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// if player tapped on inventory item
        /// then use
        /// </summary>
        /// <param name="tapPos"></param>
        public static void UseItemFromInventory(Vector2 tapPos)
        {
            //declare
            bool anyItemClicked = false;

            try
            {
                //reset the flag
                UsingItem = false;

                //if inventory is not opened then return
                if (!IsAvatarActionMenuOpen)
                {
                    return;
                }

                //first determine if player tapped on one of inventory items
                if (InventorySlots != null)
                {
                    for (int i = 0; i < InventorySlots.Count; i++)
                    {
                        if ((tapPos.X >= InventorySlots[i].Position.X && tapPos.X <= InventorySlots[i].Position.X+WorldConfig.InventorySlotWidth) && (tapPos.Y >= InventorySlots[i].Position.Y && tapPos.Y <= InventorySlots[i].Position.Y+WorldConfig.InventorySlotHeight))
                        {
                            anyItemClicked = true;
                            UsingItem = true;

                            //close the inventory
                            CloseTheInventory();

                            //player tapped on inventory item
                            Inventory[i].ItemInstance.UseItem();

                            break;
                        }


                    }
                }

                //clicked on bomb scanner?
                if (BombScanner != null)
                {
                    if ((tapPos.X >= BombScanner.Rectangle.X && tapPos.X <= BombScanner.Rectangle.X + BombScanner.Rectangle.Width) && (tapPos.Y >= BombScanner.Rectangle.Y && tapPos.Y <= BombScanner.Rectangle.Y + BombScanner.Rectangle.Height))
                    {
                        anyItemClicked = true;
                        CloseTheInventory();
                        ScannerManager.ChooseNodesToBeScanned();
                    }
                }

                //clicked on auto scanner
                if (AutoScannerInventory != null)
                {
                    if ((tapPos.X >= AutoScannerInventory.Rectangle.X && tapPos.X <= AutoScannerInventory.Rectangle.X + WorldManager.WorldConfig.InventorySlotWidth) && (tapPos.Y >= AutoScannerInventory.Rectangle.Y && tapPos.Y <= AutoScannerInventory.Rectangle.Y + WorldManager.WorldConfig.InventorySlotHeight))
                    {
                        //auto scanner enabled
                        //or disabled
                        if (ScannerManager.AutoScannerON)
                        {
                           
                            ScannerManager.AutoScannerON = false;
                            CloseTheInventory();
                        }
                        else
                        {
                            
                            ScannerManager.AutoScannerON = true;
                            CloseTheInventory();
                        }
                        
                    }
                }

                //clicked on map scanner
                if (ScannerMap != null)
                {
                    if ((tapPos.X >= ScannerMap.Rectangle.X && tapPos.X <= ScannerMap.Rectangle.X + WorldManager.WorldConfig.InventorySlotWidth) && (tapPos.Y >= ScannerMap.Rectangle.Y && tapPos.Y <= ScannerMap.Rectangle.Y + WorldManager.WorldConfig.InventorySlotHeight))
                    {
                        //map selected
                        MapScanner.ShowScannerMap();
                        anyItemClicked = true;
                        CloseTheInventory();
                    }
                }


                //if not any button in inventory tapped, then close the inventory
                if (!anyItemClicked)
                {
                    CloseTheInventory();
                }

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// remove item from the inventory
        /// </summary>
        /// <param name="item"></param>
        public static void RemoveFromInventory(Util.Classes.Item item)
        {
            try
            {
                //if 
                for (int i = 0; i < Inventory.Count; i++)
                {
                    if (Inventory[i].ID == item.Name)
                    {
                        //subtract 1 item from the inventory
                        Inventory[i].Quantity -= 1;
                        //if quantity is now 0,remove item from inventory
                        if (Inventory[i].Quantity <= 0)
                        {
                            Inventory.RemoveAt(i);
                            
                        }

                        break;
                    }
                }

               
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Prepare inventory to be displayed
        /// 1. create inventory slots and determine
        /// which is visible on the screen and which not at 
        /// the time of initialization
        /// </summary>
        public static void PrepareInventory()
        {
            //declare
            Util.Classes.InventorySlot inventorySlot;
            Util.Classes.Item item;
            Rectangle vieportRect;
            Rectangle slotRect;

            try
            {
                //cancel choosing nodes mode
                ScannerManager.ExitChooseNodesMode();

                //prepare inventory slots and items in them

                #region INVENTORY ITEMS 

                for (int i = 0; i < Inventory.Count; i++)
                {
                    item = LevelManager.GetItemByName(Inventory[i].ID);

                    //if item is not visible in inventory,then skip
                    if (!item.VisibleInInventory)
                    {
                        continue;
                    }

                    if (InventorySlots == null)
                    {
                        InventorySlots = new List<Util.Classes.InventorySlot>();
                    }

                    //new instance of inventory slot
                    inventorySlot = new Util.Classes.InventorySlot();
                    //determine position
                    if (i % 2 == 0)
                    {
                       //even
                        inventorySlot.Position = EvenSlotPos;
                        //init slot rect
                        slotRect = new Rectangle((int)EvenSlotPos.X, (int)EvenSlotPos.Y, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight);

                        //update even slot pos for the next slot
                        EvenSlotPos.X-=World.WorldManager.WorldConfig.InventorySlotWidth-(World.WorldManager.WorldConfig.InventorySlotWidth/3);
                      

                    }
                    else
                    {
                        //odd
                        inventorySlot.Position = OddSlotPos;
                        //init slot rect
                        slotRect = new Rectangle((int)OddSlotPos.X, (int)OddSlotPos.Y, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight);

                        //update odd slot pos for the next slot
                        OddSlotPos.X += World.WorldManager.WorldConfig.InventorySlotWidth + (World.WorldManager.WorldConfig.InventorySlotWidth / 3);

                    }


                    //determine if is visible
                    #region is slot visible?
                    vieportRect = new Rectangle(0, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height);
                    
                    //if rectangles intersect then slot is visible on the screen, otherwise it's not
                    if (vieportRect.Intersects(slotRect))
                    {
                        inventorySlot.IsVisible = true;
                    }
                    else
                    {
                        inventorySlot.IsVisible = false;
                    }

                    //reset rects
                    vieportRect = new Rectangle(0, 0,0,0);
                    slotRect = new Rectangle(0, 0,0,0);

                    #endregion


                    //determine if is last on left or right side
                    if (Inventory.Count % 2 == 0)
                    {
                        //if intenry count is even, then
                        //the last item is the last item in the right
                        //and last item-1 is the last item in the left
                        if (i == Inventory.Count - 1)
                        {
                            inventorySlot.IsLastRight = true;
                        }

                        if (i == (Inventory.Count - 1) - 1)
                        {
                            inventorySlot.IsLastLeft = true;
                        }


                    }
                    else
                    {
                        //if inventory count is odd, then
                        //the last item is the last item in the left
                        //and the last item-1 is the last item in the right
                        if (i == Inventory.Count - 1)
                        {
                            inventorySlot.IsLastLeft = true;
                        }

                        if (i == (Inventory.Count - 1) - 1)
                        {
                            inventorySlot.IsLastRight = true;
                        }

                        
                    }


                    //add to the collection of slots
                    InventorySlots.Add(inventorySlot);

                }

                #endregion

                #region DEVICES

                #region bomb scanner

                if (BombScanner == null)
                {
                    BombScanner = new Util.Classes.BombScannerInventory();
                }

                BombScanner.InventorySlot = new Rectangle(((Util.Cache.GraphicsDevice.Viewport.Width / 2) - World.WorldManager.WorldConfig.InventorySlotWidth / 2) - World.WorldManager.WorldConfig.InventorySlotWidth - (World.WorldManager.WorldConfig.InventorySlotWidth / 3), (Util.Cache.GraphicsDevice.Viewport.Height / 2)+(WorldConfig.InventorySlotHeight*2), WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight);                
                BombScanner.Rectangle = new Rectangle(BombScanner.InventorySlot.X,BombScanner.InventorySlot.Y,WorldConfig.InventorySlotWidth, WorldManager.WorldConfig.InventorySlotHeight);

                #endregion

                #region Auto scanner

                if (AutoScannerInventory== null)
                {
                    AutoScannerInventory = new Util.Classes.AutoScannerInventory();
                }

                //AutoScannerInventory.InventorySlot = new Rectangle((Util.Cache.GraphicsDevice.Viewport.Width / 2) - World.WorldManager.WorldConfig.InventorySlotWidth / 2, (Util.Cache.GraphicsDevice.Viewport.Height / 2) + (WorldConfig.InventorySlotHeight * 2), WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight);
                AutoScannerInventory.Rectangle = new Rectangle((Util.Cache.GraphicsDevice.Viewport.Width / 2) - World.WorldManager.WorldConfig.InventorySlotWidth / 2, (Util.Cache.GraphicsDevice.Viewport.Height / 2) + (WorldConfig.InventorySlotHeight * 2), WorldManager.WorldConfig.InventorySlotWidth, WorldManager.WorldConfig.InventorySlotHeight);

                #endregion


                #region scanner map

                if (ScannerMap == null)
                {
                    ScannerMap = new Util.Classes.ScannedNodesMapInventory();
                }

                ScannerMap.InventorySlot = new Rectangle((Util.Cache.GraphicsDevice.Viewport.Width / 2) + (World.WorldManager.WorldConfig.InventorySlotWidth / 2)+(World.WorldManager.WorldConfig.InventorySlotWidth / 3), (Util.Cache.GraphicsDevice.Viewport.Height / 2) + (WorldConfig.InventorySlotHeight * 2), WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight);
                ScannerMap.Rectangle = new Rectangle(ScannerMap.InventorySlot.X,ScannerMap.InventorySlot.Y, WorldManager.WorldConfig.InventorySlotWidth, WorldManager.WorldConfig.InventorySlotHeight);


                #endregion

                #endregion


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// draw inventory
        /// </summary>
        public static void DrawInventory()
        {
            //declare
            //float stringMeasurement=0;
            StringBuilder stringToBeShown=null;
   
            try
            {
                if (IsAvatarActionMenuOpen)
                {
                    //draw greyed out background
                    Util.Cache.Draw(Util.Cache.GetTexture("greyedOutBackground").Text2D, new Rectangle(0, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height), Color.White);

                    #region DRAW INVENTORY ITEMS

                    if (InventorySlots != null && InventorySlots.Count > 0)
                    {
                        for (int i = 0; i < InventorySlots.Count; i++)
                        {


                            //only if visible
                            if (InventorySlots[i].IsVisible)
                            {

                                //draw slot
                                Util.Cache.Draw(Util.Cache.GetTexture("inventorySlot").Text2D, new Rectangle((int)InventorySlots[i].Position.X, (int)InventorySlots[i].Position.Y, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight), Color.White);

                                //draw item
                                //get item to draw
                                //there is the same amount of inventory slots as inventory items
                                //so if current [i] is 0 then get item  0 from inventory
                                //draw
                                Util.Cache.Draw(Util.Cache.GetTexture(Inventory[i].ItemInstance.TextureName).Text2D, new Rectangle((int)InventorySlots[i].Position.X, (int)InventorySlots[i].Position.Y, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotHeight), Color.White);


                                //show item's name
                                //draw name frame
                                Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle((int)InventorySlots[i].Position.X, (int)InventorySlots[i].Position.Y - WorldConfig.InventorySlotNameFrameHeight, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotNameFrameHeight), Color.White);
                                //draw item's name
                                Util.Cache.DrawString(Util.Cache.GetFont("small").FontFace, Inventory[i].ItemInstance.Name, new Vector2((int)InventorySlots[i].Position.X + 5, (int)InventorySlots[i].Position.Y - WorldConfig.InventorySlotNameFrameHeight + 5), 15, Color.Black);

                                //show count
                                Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle((int)InventorySlots[i].Position.X, (int)InventorySlots[i].Position.Y + WorldConfig.InventorySlotHeight, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotCountFrameHeight), Color.White);
                                //draw item's name
                                Util.Cache.DrawString(Util.Cache.GetFont("small").FontFace, Inventory[i].Quantity.ToString(), new Vector2((int)InventorySlots[i].Position.X + 15, ((int)InventorySlots[i].Position.Y + WorldConfig.InventorySlotHeight) + 10), 15, Color.Black);


                            }
                        }
                    }

                    #endregion

                    #region DRAW SECRET WORD
                    //get string with covered letters that were not yet discovered
                    stringToBeShown = new StringBuilder(Levels.LevelManager.CurrentMap.ChosenSecretWord.PrepareSecretString());

                    //draw frame for secret word
                    //Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle(5,15, stringToBeShown.Length, 30), Color.White);

                    //draw the string
                    //Util.Cache.DrawString(Util.Cache.GetFont(World.WorldManager.WorldConfig.LetterFontFace).FontFace, "Secret Word: ", new Vector2(5, 15), 20, Color.Green);
                    Util.Cache.DrawString(Util.Cache.GetFont(World.WorldManager.WorldConfig.LetterFontFace).FontFace, "Secret Word: " + stringToBeShown.ToString(), new Vector2(20, 10), 15, Color.DarkRed);

                    #endregion

                    #region DRAW SCANNER

                    if (BombScanner != null)
                    {
                        //draw name frame
                        Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle((int)BombScanner.Rectangle.X, (int)BombScanner.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotNameFrameHeight), Color.White);
                        //draw item's name
                        Util.Cache.DrawString(Util.Cache.GetFont("small").FontFace, "Scanner", new Vector2((int)BombScanner.Rectangle.X + 5, (int)BombScanner.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight + 5), 15, Color.Black);

                        Util.Cache.Draw(Util.Cache.GetTexture("inventorySlot").Text2D, BombScanner.InventorySlot, Color.White);
                        Util.Cache.Draw(Util.Cache.GetTexture("BombScanner").Text2D, BombScanner.Rectangle, Color.White);
                    }

                    #endregion

                    #region AUTO SCANNER

                    if (AutoScannerInventory != null)
                    {
                        //draw name frame
                        Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle((int)AutoScannerInventory.Rectangle.X, (int)AutoScannerInventory.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotNameFrameHeight), Color.White);
                        //draw item's name
                        Util.Cache.DrawString(Util.Cache.GetFont("small").FontFace, "Auto Scanner", new Vector2((int)AutoScannerInventory.Rectangle.X + 5, (int)AutoScannerInventory.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight + 5), 15, Color.Black);



                        if (ScannerManager.AutoScannerON)
                        {
                            //draw auto scanner off-to let user know that tapping will disable auto scanner
                            Util.Cache.Draw(Util.Cache.GetTexture("AutoScannerON").Text2D, AutoScannerInventory.Rectangle, Color.White);
                        }
                        else
                        {
                            //draw auto scanner on-to let user know that tapping will enable auto scanner
                            Util.Cache.Draw(Util.Cache.GetTexture("AutoScannerOFF").Text2D, AutoScannerInventory.Rectangle, Color.White);
                        }

                    }

                    #endregion

                    #region DRAW MAP SCANNER

                    if (ScannerMap != null)
                    {
                        //draw name frame
                        Util.Cache.Draw(Util.Cache.GetTexture("MessageBox").Text2D, new Rectangle((int)ScannerMap.Rectangle.X, (int)ScannerMap.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight, WorldConfig.InventorySlotWidth, WorldConfig.InventorySlotNameFrameHeight), Color.White);
                        //draw item's name
                        Util.Cache.DrawString(Util.Cache.GetFont("small").FontFace, "The Map", new Vector2((int)ScannerMap.Rectangle.X + 5, (int)ScannerMap.Rectangle.Y - WorldConfig.InventorySlotNameFrameHeight + 5), 15, Color.Black);

                        Util.Cache.Draw(Util.Cache.GetTexture("inventorySlot").Text2D, ScannerMap.InventorySlot, Color.White);
                        Util.Cache.Draw(Util.Cache.GetTexture("ScannerMap").Text2D, ScannerMap.Rectangle, Color.White);
                    }

                    #endregion

                    #region BOMBS FOUND DEFUSED COUNT
                    

                    ////measure first string
                    //stringMeasurement=Util.Cache.GetFont("AwardPointsFont").FontFace.MeasureString("Bombs found: " + Levels.LevelManager.CurrentMap.BombFoundCount.ToString()).Length();
                    //Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, "Bombs found: " + Levels.LevelManager.CurrentMap.BombFoundCount.ToString(), new Vector2(Util.Cache.GraphicsDevice.Viewport.Width - stringMeasurement, 20), 25, Color.DarkGreen);

                    ////measure second string
                    //stringMeasurement = Util.Cache.GetFont("AwardPointsFont").FontFace.MeasureString("Bombs defused: " + Levels.LevelManager.CurrentMap.BombDefusedCount.ToString()).Length();
                    //Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, "Bombs defused: " + Levels.LevelManager.CurrentMap.BombDefusedCount.ToString(), new Vector2(Util.Cache.GraphicsDevice.Viewport.Width - stringMeasurement, 50), 25, Color.Green);

                    ////measure second string
                    //stringMeasurement = Util.Cache.GetFont("AwardPointsFont").FontFace.MeasureString("Bombs total: " + Levels.LevelManager.CurrentMap.TotalBombCount.ToString()).Length();
                    //Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, "Bombs total: " + Levels.LevelManager.CurrentMap.TotalBombCount.ToString(), new Vector2(Util.Cache.GraphicsDevice.Viewport.Width - stringMeasurement, 80), 25, Color.Purple);


                    //stringMeasurement = -1;
                    #endregion

                    InventoryClosed = false;


                }
                else
                {
                    InventoryClosed = true;
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion


        #endregion

        #endregion

    }
}
